//
//  GYMineBuyInfoDetailViewModel.m
//  GYDemo
//
//  Created by mac on 2018/3/27.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "GYMineBuyInfoDetailViewModel.h"
#import "Head.h"

@implementation GYMineBuyInfoDetailSpecialPropertyModel
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{
             @"productTypeProperty":@"productTypeProperty",
             @"list":@"list",
             @"code" : @"productTypeProperty.code",
             @"idField" : @"productTypeProperty.id",
             @"name" : @"productTypeProperty.name",
             @"protypeid" : @"productTypeProperty.protypeid",
             @"search" : @"productTypeProperty.search",
             @"sort" : @"productTypeProperty.sort",
             @"status" : @"productTypeProperty.status",
             @"tlevel":@"productTypeProperty.tlevel",
             @"type" : @"productTypeProperty.type"
             };
}
@end

@implementation GYMineBuyInfoDetailModel

+ (NSDictionary *)modelCustomPropertyMapper {
    return @{
             @"address" : @"address",
             @"area" : @"area",
             @"areas" : @"areas",
             @"buyaddress" : @"buyaddress",
             @"buyid" : @"buyid",
             @"city" : @"city",
             @"companyname" : @"companyname",
             @"count":@"count",
             @"createtime":@"createtime",
             @"descriptionField":@"description",
             @"down":@"down",
             @"endtime":@"endtime",
             @"idField":@"id",
             @"linkmobile":@"linkmobile",
             @"lname":@"lname",
             @"maxprice":@"maxprice",
             @"minprice":@"minprice",
             @"name":@"name",
             @"pid":@"pid",
             @"protypeid":@"protypeid",
             @"protypename":@"protypename",
             @"province":@"province",
             @"qq":@"qq",
             @"specialproperty":@"specialproperty",
             @"status":@"status",
             @"topid":@"topid",
             @"topip":@"topip",
             @"unit":@"unit"
             };
}

@end

@implementation GYMineBuyInfoDetailViewModel
#pragma mark - getter and setter
-(NSString *)name
{
    return self.buyInfoDetailModel.name;
}
-(NSString *)type
{
    NSString *types = [NSString stringWithFormat:@"%@",self.buyInfoDetailModel.protypename];
    return types;
}
-(NSString *)price
{
    NSString *prices = [NSString stringWithFormat:@"%ld - %ld元/%@",self.buyInfoDetailModel.minprice,self.buyInfoDetailModel.maxprice,self.buyInfoDetailModel.unit];
    return prices;
}
-(NSString *)area
{
    return self.buyInfoDetailModel.buyaddress;
}
-(NSString *)count
{
    return [NSString stringWithFormat:@"%ld",self.buyInfoDetailModel.count];
}
-(NSString *)endDate
{
    return self.buyInfoDetailModel.endtime;
}
-(NSString *)serverCount
{
    return [NSString stringWithFormat:@"供货%ld笔",self.serverDataSource.count];
}
-(NSString *)createDate
{
    return self.buyInfoModel.createtime;
}
-(NSString *)descriptions
{
    return self.buyInfoDetailModel.descriptionField;
}
#pragma mark - method
-(void)requestDetail
{
    @WeakSelf;
    NSMutableDictionary *para = [NSMutableDictionary new];
    NSString *ids = [NSString stringWithFormat:@"%ld",_buyInfoModel.id];
    [para setObject:ids forKey:@"id"];
    NSString *interface = @"buyProductDetail";
    [[InterfaceManager shareInterface]requetInterface:interface withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        NSDictionary *data = infoModel.data;
        if ([data isKindOfClass:[NSDictionary class]]) {
            GYMineBuyInfoDetailModel *detailModel = [GYMineBuyInfoDetailModel yy_modelWithJSON:data];
            [selfp setBuyInfoDetailModel:detailModel];
        }
    }];
    [self requestServers];
}
-(void)requestServers
{
    @WeakSelf;
    NSMutableDictionary *para = [NSMutableDictionary new];
    NSString *ids = [NSString stringWithFormat:@"%ld",_buyInfoModel.id];
    [para setObject:ids forKey:@"productid"];
    NSString *interface = @"buySupply";
    [[InterfaceManager shareInterface]requetInterface:interface withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        if (0 == infoModel.status) {
            id data = infoModel.data;
            NSArray *arr;
            NSMutableArray *marr = [NSMutableArray new];
            if ([data isKindOfClass:[NSArray class]]) {
                arr = data;
            }
            if ([data isKindOfClass:[NSDictionary class]]) {
                arr = [(NSDictionary *)data objectForKey:@"datalist"];
            }
            for (NSDictionary *dic in arr) {
                GYMineLikeProductInfoModel *model = [GYMineLikeProductInfoModel yy_modelWithJSON:dic];
                [marr addObject:model];
            }
            [selfp setServerDataSource:marr];
        }else{
           // [FTIndicator showInfoWithMessage:@"暂无供货信息~"];
        }
    }];
}
#pragma mark - life
-(instancetype)init
{
    if (self = [super init]) {
        [[InterfaceManager shareInterface].specialInterfaces addObject:@"buySupply"];
    }
    return self;
}
@end
